package com.ywu.application.standard.thirdExec.api;

import com.ywu.common.gson.GsonUtils;
import com.ywu.common.result.CommonResult;
import com.ywu.application.standard.thirdExec.dto.YwuThirdExecDto;
import com.ywu.application.standard.thirdExec.dto.YwuThirdExecParamListDto;
import com.ywu.application.standard.thirdExec.service.YwuThirdExecService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName YwuThirdExecApi
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/10/11 14:48
 * @Version 1.0
 **/
@RestController
@RequestMapping("/ywu/third/exec")
public class YwuThirdExecApi {
    @Autowired
    private YwuThirdExecService service;

    /**
    * @Author GroundDemo
    * @Description 添加脚本执行内容
    * @Date 14:51 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/create.third.exec.info")
    public CommonResult<Object> createThirdExec(@RequestBody YwuThirdExecParamListDto ywuThirdExecParamListDto) {
        YwuThirdExecDto ywuThirdExecDto = new YwuThirdExecDto();
        BeanUtils.copyProperties(ywuThirdExecParamListDto, ywuThirdExecDto, "execParam");
        ywuThirdExecDto.setExecParam(GsonUtils.serialize(ywuThirdExecParamListDto.getExecParam()));
        return service.createThirdExec(ywuThirdExecDto);
    }

    /**
    * @Author GroundDemo
    * @Description 更新脚本元信息内容
    * @Date 14:52 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/update.third.exec.info")
    public CommonResult<Object> updateThirdExec(@RequestBody YwuThirdExecParamListDto ywuThirdExecParamListDto) {
        YwuThirdExecDto ywuThirdExecDto = new YwuThirdExecDto();
        BeanUtils.copyProperties(ywuThirdExecParamListDto, ywuThirdExecDto, "execParam");
        ywuThirdExecDto.setExecParam(GsonUtils.serialize(ywuThirdExecParamListDto.getExecParam()));
        return service.updateThirdExec(ywuThirdExecDto);
    }

    /**
    * @Author GroundDemo
    * @Description 删除脚本信息
    * @Date 14:53 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/delete.third.exec.info")
    public CommonResult<Object> deleteThirdExec(@RequestBody YwuThirdExecDto ywuThirdExecDto) {
        return service.deleteThirdExec(ywuThirdExecDto);
    }

    /**
    * @Author GroundDemo
    * @Description 分页查询脚本信息数据
    * @Date 14:55 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/query.third.exec.info.page")
    public CommonResult<Object> queryThirdExecPageList(@RequestBody YwuThirdExecDto ywuThirdExecDto) {
        return service.queryThirdExecPageList(ywuThirdExecDto);
    }

    /**
    * @Author GroundDemo
    * @Description 上传执行脚本文件
    * @Date 11:44 2024/10/12
    * @Param [file, id]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/upload.third.exec.file")
    public CommonResult<Object> uploadThirdExecFile(@RequestParam("file") MultipartFile file, @RequestParam("id") String id) {
        return service.uploadThirdExecFile(file, id);
    }

    /**
    * @Author GroundDemo
    * @Description 发布脚本信息
    * @Date 12:45 2024/10/12
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/publish.third.exec.info")
    public CommonResult<Object> publishThirdExecInfo(@RequestBody YwuThirdExecDto ywuThirdExecDto) {
        return service.publishThirdExecInfo(ywuThirdExecDto);
    }

    /**
    * @Author GroundDemo
    * @Description 执行脚本
    * @Date 14:59 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/do.third.exec.id")
    public CommonResult<Object> doThirdExec(@RequestBody YwuThirdExecParamListDto ywuThirdExecParamListDto) {
        YwuThirdExecDto ywuThirdExecDto = new YwuThirdExecDto();
        BeanUtils.copyProperties(ywuThirdExecParamListDto, ywuThirdExecDto, "execParam");
        ywuThirdExecDto.setExecParam(GsonUtils.serialize(ywuThirdExecParamListDto.getExecParam()));
        return service.doThirdExec(ywuThirdExecDto);
    }

    /**
    * @Author GroundDemo
    * @Description 分页查询执行日志
    * @Date 15:03 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/query.third.exec.log.page")
    public CommonResult<Object> queryThirdExecLog(@RequestBody YwuThirdExecDto ywuThirdExecDto) {
        return service.queryThirdExecLog(ywuThirdExecDto);
    }
}
